<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
    <head>
        <th:block th:include="include :: header('修改')"/>
        <th:block th:include="include :: bootstrap-fileinput-css"/>
    </head>
    <body class="white-bg">
        <div class="wrapper wrapper-content animated fadeInRight ibox-content">
            <form class="form-horizontal m" id="form-coursedetail-edit" th:object="${bizCourseDetail}">
                <input name="id" th:field="*{id}" type="hidden">
                <div class="form-group">
                    <label class="col-sm-3 control-label">所属课程：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input id="treeId" name="courseId" type="hidden" th:value="*{courseId}"/>
                            <input class="form-control" type="text" onclick="selectManageTree()" id="treeName"
                                   readonly="true" th:value="*{courseName}">
                            <span class="input-group-addon"><i class="fa fa-search"></i></span>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">标题：</label>
                    <div class="col-sm-8">
                        <input name="title" th:field="*{title}" class="form-control" type="text">
                    </div>
                </div>
                <!--            <div class="form-group">-->
                <!--                <label class="col-sm-3 control-label">封面图片：</label>-->
                <!--                <div class="col-sm-8">-->
                <!--                    <input name="coverUrl" th:field="*{coverUrl}" class="form-control" type="text">-->
                <!--                </div>-->
                <!--            </div>-->
                <div class="form-group">
                    <label class="col-sm-3 control-label">课程介绍：</label>
                    <div class="col-sm-8">
                        <textarea name="introduce" class="form-control">[[*{introduce}]]</textarea>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">讲师：</label>
                    <div class="col-sm-8">
                        <select name="teacher" class="form-control m-b"
                                th:with="type=${@bizCourseExpertServiceImpl.selectBizCourseExpertList()}">
                            <option value="">请选择</option>
                            <option th:each="dict : ${type}" th:text="${dict.name}" th:value="${dict.id}"
                                    th:field="*{teacher}"></option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">课件资料：</label>
                    <div class="col-sm-8">
                        <input name="pptUrl" th:field="*{pptUrl}" id="pptUrl" class="form-control" type="hidden">
                        <input name="host" th:field="*{host}" id="host" class="form-control" type="hidden">
                        <div class="file-loading">
                            <input class="file" type="file" id="ppt" name="file" data-min-file-count="1"
                                   data-theme="fas" data-show-preview="false">
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">视频资料：</label>
                    <div class="col-sm-8">
                        <input name="videoUrl" th:field="*{videoUrl}" id="videoUrl" class="form-control" type="hidden">
                        <div class="file-loading">
                            <input class="file" type="file" id="video" name="file" data-min-file-count="1"
                                   data-theme="fas" data-show-preview="false">
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">显示顺序：</label>
                    <div class="col-sm-8">
                        <input name="orderNum" th:field="*{orderNum}" class="form-control" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">状态：</label>
                    <div class="col-sm-8">
                        <select name="visible" class="form-control m-b"
                                th:with="type=${@dict.getType('biz_visible_status')}">
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                                    th:field="*{visible}"></option>
                        </select>
                    </div>
                </div>
            </form>
        </div>
        <th:block th:include="include :: footer"/>
        <th:block th:include="include :: bootstrap-fileinput-js"/>
        <script type="text/javascript">
            var prefix = ctx + "biz/coursedetail";

            function submitHandler() {
                if ($.validate.form()) {
                    $.operate.save(prefix + "/edit", $('#form-coursedetail-edit').serialize());
                }
            }

            function selectManageTree() {
                var options = {
                    title: '课程选择',
                    width: "380",
                    url: prefix + "/selectManageTree/" + $("#treeId").val(),
                    callBack: doSubmit
                };
                $.modal.openOptions(options);
            }

            function doSubmit(index, layero) {
                var tree = layero.find("iframe")[0].contentWindow.$._tree;
                if (checkL3(tree)) {
                    var body = layer.getChildFrame('body', index);
                    $("#treeId").val(10000 + Number.parseInt(body.find('#treeId').val())); // 转换为真实的id
                    $("#treeName").val(body.find('#treeName').val());
                    console.log('courseid = ' + $("#treeId").val())
                    layer.close(index);
                }
            }

            function checkL3(_tree) {
                var nodes = _tree.getSelectedNodes();
                if (nodes.length == 0) {
                    $.modal.msgError("请选择节点后提交");
                    return false;
                }
                for (var i = 0; i < nodes.length; i++) {
                    if (nodes[i].level != 2) {
                        $.modal.msgError("只能选择第三级目录");
                        return false;
                    }

                }
                return true;
            }

            $("#ppt").fileinput({
                                    'theme': 'explorer-fas',
                                    'uploadUrl': ctx + "common/uploadPPT",
                                    language: 'zh',
                                    allowedFileExtensions: ['ppt', 'pptx'],
                                    dropZoneEnabled: false,
                                    maxFileCount: 1,
                                    autoReplace: true,
                                    initialPreviewAsData: true, // 回显数据设置
                                    overwriteInitial: true,
                                    previewFileType: ['other'],
                                    initialPreview: [],
                                    layoutTemplates: {
                                        actionUpload: '',//去除上传预览缩略图中的上传图片
                                        //actionZoom:'',   //去除上传预览缩略图中的查看详情预览的缩略图标
                                        //actionDownload:'' //去除上传预览缩略图中的下载图标
                                        //actionDelete:'', //去除上传预览的缩略图中的删除图标
                                    },
                                    showUploadedThumbs: false,
                                    showUpload: false,
                                }).on("filebatchselected", function (event, data) {//选择即上传
                console.log(event)
                console.log('-----------data-----------')
                console.log("有符合的文件:" + !!!data[0])
                console.log(JSON.stringify(data))
                if (!!!data[0]) {
                    $(this).fileinput("upload") // 上传文件
                }
            }).on("fileuploaded", function (event, data, previewId, index) {
                console.log(event)
                console.log(data)
                const result = data.response
                if (+result.code == +web_status.SUCCESS) {
                    $('#pptUrl').val(result.url)
                    $('#host').val(result.host)
                } else {
                    $.modal.alertError(result.msg);
                }
                console.log('图路径:' + $('#pptUrl').val())
                var id = $('#id').val()
                var pptData = {
                    id,
                    pptUrl:result.url
                }
                $.post(prefix + "/edit",pptData)
            })

            $("#video").fileinput({
                                      'theme': 'explorer-fas',
                                      'uploadUrl': ctx + "common/upload",
                                      language: 'zh',
                                      allowedFileExtensions: ["mp4", "avi", "dat", "3gp", "mov", "rmvb", "flv", "mkt"],
                                      dropZoneEnabled: false,
                                      maxFileCount: 1,
                                      autoReplace: true,
                                      initialPreviewAsData: true, // 回显数据设置
                                      overwriteInitial: true,
                                      previewFileType: ['video'],
                                      initialPreview: [],
                                      layoutTemplates: {
                                          actionUpload: '',//去除上传预览缩略图中的上传图片
                                          //actionZoom:'',   //去除上传预览缩略图中的查看详情预览的缩略图标
                                          //actionDownload:'' //去除上传预览缩略图中的下载图标
                                          //actionDelete:'', //去除上传预览的缩略图中的删除图标
                                      },
                                      showUploadedThumbs: false,
                                      showUpload: false,
                                  }).on("filebatchselected", function (event, data) {//选择即上传
                if (!!!data[0]) {
                    $(this).fileinput("upload") // 上传文件
                }
            }).on("fileuploaded", function (event, data, previewId, index) {
                console.log(event)
                console.log(data)
                const result = data.response
                if (+result.code == +web_status.SUCCESS) {
                    $('#videoUrl').val(result.url)
                    $('#host').val(result.host)
                } else {
                    $.modal.alertError(result.msg);
                }
                console.log('视频路径:' + $('#videoUrl').val())
                var id = $('#id').val()
                var pptData = {
                    id,
                    videoUrl:result.url
                }
                $.post(prefix + "/edit",pptData)
            })
        </script>
    </body>
</html>